﻿<ul class="unit-grid invoice card">
@if((Model.Items as IEnumerable<dynamic>).Any())
{
    foreach(var i in Model.Items)
    {
        string status = String.Empty;
        if(JDM.HasFlags(i.Flags, "Canceled"))
        {
            status = "Canceled";
        }
        else if(JDM.HasFlags(i.Flags, "Pending"))
        {
            status = "Pending";
        }
        else if(JDM.HasFlags(i.Flags, "Issued"))
        {
            status = "Issued";
        }
        else if(JDM.HasFlags(i.Flags, "Paid"))
        {
            status = "Paid";
        }
        <li class="unit invoice card @(!JDM.HasFlags(i.Flags, "Active") ? "inactive" : String.Empty)">
            <header>
                @T(Res.Name("Invoice"), 
                    JDM.Int32(i.EntityID), 
                    Svc.Date((DateTime)JDM.DateTime(i.IssuedOn)), 
                    T(Res.In("API").Of("Enum").Of("InvoiceFlags").Name(status)))
            </header>
            <section>
                <table class="key-value highlight-key">
                    <tr>
                        <td>@T(Res.Name("Order"))</td>
                        <td><a href="@Url.Action(Loc.Act("Show").Ctrl("Order").Set(new
                        {
                            id = JDM.Int32(i.Order.EntityID)
                        }).Localized())">@JDM.String(i.Order.Guid)</a></td>
                    </tr>
                    <tr>
                        <td>@T(Res.In("Common").Of("Vocab").Name("Guid"))</td>
                        <td>@JDM.String(i.Guid)</td>
                    </tr>
                    <tr>
                        <td>@T(Res.Name("RefundAmount"))</td>
                        <td>@Svc.Price((decimal)JDM.Decimal(i.RefundAmount))</td>
                    </tr>
                    <tr>
                        <td>@T(Res.Name("PaidAmount"))</td>
                        <td>@Svc.Price((decimal)JDM.Decimal(i.PaidAmount))</td>
                    </tr>
                    <tr>
                        <td>@T(Res.Name("Total"))</td>
                        <td>@Svc.Price((decimal)JDM.Decimal(i.Total))</td>
                    </tr>
                </table>
            </section>
            <footer>
                <ul class="bar inlinebar">
                    <li><a href="@Url.Action(Loc.Act("PdfReport").Set(new
                    {
                        id = JDM.Int32(i.EntityID)
                    }).Localized())">@T(Res.Name("PdfReport"))</a></li>
                    @if(JDM.HasFlags(i.Flags, "Issued"))
                    {
                        <li><a href="@Url.Action(Loc.Act("Place").Ctrl("Payment").Set(new
                        {
                            invoiceID = JDM.Int32(i.EntityID),
                            amount = Svc.Price((decimal)JDM.Decimal(i.Total))
                        }).Localized())">@T(Res.Name("PlacePayment"))</a></li>
                    }
                </ul>
            </footer>
        </li>
    }
}
else
{
    <li class="empty"><span>@T(Res.In("Common").Of("Expr").Name("NoData"))</span></li>
}
</ul>

